package com.xt.favorites.admin.service.impl;

import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.util.internal.StringUtil;
import com.xt.common.utils.DateUtils;
import com.xt.favorites.admin.entity.Favorites;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xt.common.utils.PageUtils;
import com.xt.common.utils.Query;

import com.xt.favorites.admin.dao.FavoritesDao;
import com.xt.favorites.admin.entity.FavoritesEntity;
import com.xt.favorites.admin.service.FavoritesService;

import javax.annotation.Resource;


@Service("favoritesService")
public class FavoritesServiceImpl extends ServiceImpl<FavoritesDao, FavoritesEntity> implements FavoritesService {

    @Resource
    FavoritesDao favoritesDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<FavoritesEntity> page = this.page(
                new Query<FavoritesEntity>().getPage(params),
                new QueryWrapper<FavoritesEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<Map<String, Integer>> console() {
        List<Map<String,Integer>> result = new ArrayList<Map<String, Integer>>();
        Map<String, Integer> collectAll = favoritesDao.getCollectAll();
        Map<String, Integer> collectTroday = favoritesDao.getCollectToday();
        result.add(collectAll);
        result.add(collectTroday);

        return result;
    }
    //保存默认收藏夹
    @Override
    public FavoritesEntity saveFavorites(Long userId, String unReadList) {
        FavoritesEntity favoritesEntity = new FavoritesEntity();
        Favorites favorites = new Favorites();
        favorites.setName(unReadList);
        favorites.setUserId(userId);
        favorites.setCount(0l);
        favorites.setPublicCount(10l);
        favorites.setCreateTime(DateUtils.getCurrentTime());
        favorites.setLastModifyTime(DateUtils.getCurrentTime());
        BeanUtils.copyProperties(favorites,favoritesEntity);
        this.save(favoritesEntity);
        return  favoritesEntity;


    }

}